#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<ctime>
//#include<opencv2/core/core.hpp>
//#include<opencv2/highgui/highgui.hpp>

#include"common.h"
#include"object.h"
#include"bmp.h"
#include"scene.h"
#include"camera.h"
#include"log.h"
#include"raytracer.h"
#define fo(i,a,b) for(int i = a;i<=b;i++)
using namespace std;

int row;
int colon;

Scene *scene;
Camera *camera;


//void opencvOutput(){
//        cv::Mat m(row, colon, CV_8UC3, cv::Scalar(0, 0, 0));
//        for ( int i = 0 ; i < row ; i++ )
//            for ( int j = 0 ; j < colon ; j++ ){
//                cv::Vec3b pixcel;
//                pixcel[0] = camera->ima[i][j].b;
//                pixcel[1] = camera->ima[i][j].g;
//                pixcel[2] = camera->ima[i][j].r;
//                m.at<cv::Vec3b>(i,j) = pixcel;
//            }
//        cv::namedWindow("canvas",cv::WINDOW_NORMAL);
//        imshow("canvas", m);
//        cv::waitKey();
//}

Log *ww = new Log();

int main(int argc, char* argv[]){
    srand(time(0));

//=============网格简化==============
    ComplexObj obj = ComplexObj("dragon.obj");
	clock_t startTime = clock();
    obj.simplified(0.01);
	
	printf("execution time : %.2f ms\n", (double)(clock() - startTime));
    obj.output("result.obj");

//=============光线追踪==============

//    cout << "input row and colon!" << endl;
//    row = colon = 500;


//    Scene* scene = new Scene();

//    ComplexObj* room = new ComplexObj("ta.obj");
//    scene->addObject(room);
////    ComplexObj* dragon = new ComplexObj("dragon.obj");
////    scene->addObject(dragon);
////    Sphere* ball1 = new Sphere(Vec(3, 20, -8), 1, "sphere", Material(0, 0, 1, 0 ,RGB(1, 0 ,0)));
////    scene->addObject(ball1);
////    Sphere* ball2 = new Sphere(Vec(0, 17, -8), 1, "sphere", Material(0, 0, 1, 0 ,RGB(0, 1 ,0)));
////    scene->addObject(ball2);
////    ComplexObj* box = new ComplexObj("box.obj");
////    scene->addObject(box);
////    ComplexObj* bunny = new ComplexObj("rabbit.obj");
////    scene->addObject(bunny);
////    ComplexObj* bug = new ComplexObj("bug.obj");
////    scene->addObject(bug);
//    ComplexObj* toy = new ComplexObj("toy.obj");
//    scene->addObject(toy);

//    camera = new Camera(Vec(0, 7, 0), Vec(0, 10, 0), Vec(0, 0, 1), scene);

//    RayTracer *rayTracer = new RayTracer(scene, camera);
//    rayTracer->antiAliasing = 1;
//    rayTracer->refDep = 0;
//    rayTracer->setHW(row, colon);
//    rayTracer->startRayTracing();
//    rayTracer->outputBmp();
//    //rayTracer->outputOpencv();







    return 0;
}
